package gin

import (
	"gitee.com/zawei/yggdrasil/pkg/config"
	"gitee.com/zawei/yggdrasil/pkg/log"
	"gitee.com/zawei/yggdrasil/pkg/transport/server"
	"github.com/gin-gonic/gin"
)

var svr *Server

func init() {
	c := new(Config)
	if err := config.Get("server.http").Scan(c); err != nil {
		log.Fatalw("fault to scan http config", "error", err)
	}
	svr = c.Build()
	server.RegisterServer(svr)
}

func WithInterceptor(mid ...gin.HandlerFunc) {
	svr.Use(mid...)
}

func RegisterService(desc *ServiceDesc, service interface{}, middle ...gin.HandlerFunc) {
	svr.RegisterService(desc, service, middle...)
}

func RegisterHandler(httpMethod, relativePath string, handlers ...gin.HandlerFunc) {
	svr.Handle(httpMethod, relativePath, handlers...)
}
